package com.ctshk.rpc.train.service;

import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.ChannelMainData;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.model.TokenUser;
import com.ctshk.rpc.train.dto.*;
import com.ctshk.rpc.train.dto.es.TrainProductCacheDTO;
import com.ctshk.rpc.train.req.*;

import java.time.LocalDate;
import java.util.List;

/**
 * <p>
 * 火车票产品表 服务类
 * </p>
 *
 * @author 彭柳霖
 * @since 2021-03-11
 */
public interface ITrainProductService{

    /**
     * 资源中心-分页查询火车票产品列表
     * @param trainProductPageReq
     * @return
     */
    PageResponse<TrainProductPageDTO> queryList(TrainProductPageReq trainProductPageReq);


    /**
     * 新增火车票产品信息
     * @param trainProductReq
     * @param user
     */
    Result saveTrainProduct(TrainProductReq trainProductReq, TokenUser user);



    /**
     * 新增火车产品预订信息
     * @param reservationSettingsReq
     * @param user
     */
    Result saveReservation(TrainProductReservationSettingsReq reservationSettingsReq, TokenUser user);


    /**
     * 修改火车产品预订信息
     * @param reservationSettingsReq
     * @param user
     */
    Result updateReservation(TrainProductReservationSettingsReq reservationSettingsReq, TokenUser user);


    /**
     * 新增-编辑提交审批
     * @param id
     * @param user
     */
    Result submit(Long id, TokenUser user);


    /**
     * 修改审核通过火车票产品
     */
    Result updateApprovedTrainProduct(TrainProductReq trainProductReq, TokenUser user);


    /**
     * 修改审核不通过火车票产品
     */
    Result updateUnapprovedTrainProduct(TrainProductReq trainProductReq, TokenUser user);


    /**
     * 查询火车票产品详情信息
     * @param id
     * @return
     */
    TrainProductDTO queryDetail(Long id);


    /**
     * api设置
     * @param trainProductSetReq
     */
    Result setApi(TrainProductSetReq trainProductSetReq, TokenUser user);

    /**
     * 有效无效设置
     * @param id
     */
    Result setValid(Long id, TokenUser user);

    /**
     * 批量设置
     * @param batchTrainProductInfoReq
     */
    Result batchSetting(BatchTrainProductInfoReq batchTrainProductInfoReq, TokenUser user);


    /**
     * 推荐设置
     * @param id
     */
    Result setRecommended(Long id, TokenUser user);


    /**
     * 查询火柴票推荐列表
     */
    List<RecommendedTrainDTO> queryRecommendedBusTicket(Long userId, RecommendedBusTicketReq req);


    /**
     * 预订中心-分页查询火车票
     * @param busPageReq
     * @return
     */
    PageResponse<ReservationTrainPageDTO> queryReservationBusList(ReservationTrainPageReq busPageReq, Long userId);


    /**
     * 根据火车票产品id和用户id，查询用户自营下的加幅后价格和余票信息,售出数量增加
     *
     * @param trainProductId
     * @param touristNumber
     * @param userId
     * @param effectiveTime
     * @return
     */
    TrainPriceRemainderDTO selectSelfPriceRemainderAndLock(Long trainProductId, int touristNumber, Long userId, LocalDate effectiveDate);

    /**
     * 根据火车票产品id和用户id，查询用户代理下的加幅后价格和余票信息,售出数量增加
     *
     * @param busProductId
     * @param touristNumber
     * @param userId
     * @param effectiveDate
     * @return
     */
    TrainPriceRemainderDTO selectAgentPriceRemainderAndLock(Long busProductId, int touristNumber, Long agentId, Long userId, LocalDate effectiveDate);

    /**
     *获取机票旅客类型
     * @return
     */
    List<TrainTouristTypeDTO> queryTouristType();

    /**
     * 运营中心查询火车产品列表
     * @param req
     * @return
     */
    Result<PageResponse<TrainProductDTO>> queryProductListForIotc(TrainProductListForIotcQueryReq req);

    /**
     * 运营中心根据ID查询火车产品列表
     * @param idList
     * @return
     */
    Result<List<TrainProductDTO>> queryProductListByIdForIotc(List<Long> idList);

    /**
     * 更新審批狀態
     * @param trainProductCheckReq
     * @param currentUser
     * @return
     */
    Result<Long> check(TrainProductCheckReq trainProductCheckReq, TokenUser currentUser);

    /**
     * 查询预订用的代理商信息列表
     * @param req
     * @return
     */
    Result<List<TrainProductReservationAgentDTO>> queryReservationAgentList(TrainProductReservationAgentQueryReq req, TokenUser currentUser);

    List<TrainProductCacheDTO> queryTrainProductList(List<String> trainNumberNames);

    TrainPriceRemainderDTO selectAppPriceRemainderAndLock(Long trainProductId, int touristNumber, LocalDate effectiveDate, ChannelMainData mainData);

    /**
     * 查询火车产品售价信息逻辑处理
     * @param strategyType 加幅类型，1：自营；2：代理；3：官方平台；4：第三方平台；
     * @param productId 产品ID
     * @param departureDate 出发日期
     * @param relId 关联ID，strategyType(1：用户ID；2：代理ID；3：渠道ID；4：渠道ID)
     * @return
     */
    TrainPriceRemainderDTO findTrainSalePriceInfoHandle(int strategyType, Long productId, LocalDate departureDate, Long relId);

    /**
     * 查询火车产品售价信息 - 线下自营
     * @return
     */
    default TrainPriceRemainderDTO findTrainSalePriceInfoOfflineSelf(Long productId, LocalDate departureDate, Long userId) {
        return findTrainSalePriceInfoHandle(1, productId, departureDate, userId);
    }

    /**
     * 查询火车产品售价信息 - 线下代理
     * @return
     */
    default TrainPriceRemainderDTO findTrainSalePriceInfoOfflineAgent(Long productId, LocalDate departureDate, Long agentId) {
        return findTrainSalePriceInfoHandle(2, productId, departureDate, agentId);
    }

    /**
     * 查询火车产品售价信息 - 官方平台
     * @return
     */
    default TrainPriceRemainderDTO findTrainSalePriceInfoOnlineSelf(Long productId, LocalDate departureDate, Long channelId) {
        return findTrainSalePriceInfoHandle(3, productId, departureDate, channelId);
    }
}
